package com.file;

import java.io.File;
import java.io.IOException;

import org.codehaus.plexus.util.FileUtils;

public class TestResE {
	static final String Suffix = "_";
	public static void main(String[] args) throws IOException {
		
		File f = new File("E:\\pro\\workPro\\cx\\newPro1");
		//System.out.println(f.getName());
		File[] temp = f.listFiles();
		for(int i =0; i<temp.length; i++) {
			//System.out.println(temp[i].getName());
			if(temp[i].isDirectory()) {
				listFile(temp[i].listFiles(),1);
			}else{
				if(getFileFix(temp[i].getName()).equals("java_")){
					System.out.println(temp[i].getName());
					System.out.println(temp[i].getParentFile());
					System.out.println(getNewFile(temp[i].getName()));
					
					FileUtils.copyFile(temp[i], new File(temp[i].getParentFile()+"\\"+getNewFile(temp[i].getName())));
					temp[i].delete();
				}
			}
		}
		
		//listFile(f.listFiles(), 1);
	}
	
	static void listFile(File[] f, int n) throws IOException {
		String s = "";
		for(int i = 0; i<n; i++ ) {
			s +="    ";
		}
		
		for(int j=0; j<f.length; j++) {
			//System.out.println(s + f[j].getName());
			if(f[j].isDirectory()) {
				listFile(f[j].listFiles(), n+1);
			}else{
				if(getFileFix(f[j].getName()).equals("java_")){
					System.out.println(s + f[j].getName());
					System.out.println(f[j].getParentFile());
					System.out.println(getNewFile(f[j].getName()));
					
					FileUtils.copyFile(f[j], new File(f[j].getParentFile()+"\\"+getNewFile(f[j].getName())));
					f[j].delete();
					
				}
			}
		}
		
	}
	
	static String getFileFix(String fileName){
		String fix ="";

		if(fileName.lastIndexOf(".")!=-1){
			fix = fileName.substring(fileName.lastIndexOf(".")+1,fileName.length());
		}
		return fix;
		
	}
	
	static String getNewFile(String fileName){
		String newFileName ="";

		if(fileName.lastIndexOf("_")!=-1){
			newFileName = fileName.substring(0,fileName.length()-1);
		}
		return newFileName;
		
	}
}